package com.app.designpatternslearn.behavior.interpreterpattern

import com.app.designpatternslearn.behavior.interpreterpattern.code.AbstractExpression
import com.app.designpatternslearn.behavior.interpreterpattern.code.AndExpression
import com.app.designpatternslearn.behavior.interpreterpattern.code.TerminalExpression
import com.app.designpatternslearn.behavior.interpreterpattern.code.OrExpression


//规则：Robert 和 John 是男性
fun getMaleExpression(): AbstractExpression {
    val robert = TerminalExpression("Robert")
    val john = TerminalExpression("John")
    return OrExpression(robert, john)
}

//规则：Julie 是一个已婚的女性
fun getMarriedWomanExpression(): AbstractExpression {
    val julie = TerminalExpression("Julie")
    val married = TerminalExpression("Married")
    return AndExpression(julie, married)
}

fun main() {

    val isMale = getMaleExpression()
    val isMarriedWoman = getMarriedWomanExpression()

    println("John is male? ${isMale.interpret("John")}")
    println("Julie is a married women? ${isMarriedWoman.interpret("Married Julie")}")

}